<template>
	<view>
		<uni-list><uni-list-item v-for="(value, key, index) in info" :key="index" :title="key" :note="value + ''"></uni-list-item></uni-list>

		<view style="margin-top: 300rpx;">监听网络状态变化把值改成2。</view>
		<view>{{ value }}</view>
		<view>{{ network.isConnected }}</view>
		<view>{{ network.networkType }}</view>
		<button type="default" @click="offnetwork">取消监听,网络再改变时，值不会变</button>
	</view>
</template>

<script>
export default {
	data() {
		return {
			info: {},
			value: 1,
			network: {}
		};
	},
	onLoad() {
		this.getNetworkType()
		this.onNetwork(); //监听
	},
	methods: {
		getNetworkType(){
			let _this = this;
			uni.showToast({
				title:'获取状态',
				icon:'none'
			})
			uni.getNetworkType({
				success: function(d) {
					console.log(d);
					_this.info={};
					_this.info = d;
				}
			});
		},
		changeValue(){
			let _this = this;
			this.value = 2;
			this.getNetworkType()
		},
		onNetwork() {
			uni.onNetworkStatusChange(this.changeValue);
		},
		offnetwork() {
			uni.offNetworkStatusChange(this.changeValue)
		}
	}
};
</script>

<style></style>
